﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace chessLogic
{
    public class Knight : Figure
    {
        public Knight(FigureColor color) : base(color, FigureType.Knight) { }
        public override List<Position> GetPossiblyPositionNormalMove(Position position,Board board)
        { 
            List<Position> retList = new List<Position>();
            List<Position> positions = GetPossiblyPosition(position, board);
            foreach (Position pos in positions)
                if (pos.IsOnBoard() && board.IsPositionEmpty(pos))
                    retList.Add(pos);
            return retList;
        }
        public override List<Position> GetPossiblyPositionTakingMove(Position position,Board board)
        {
            List<Position> retList = new List<Position>();
            List<Position> positions = GetPossiblyPosition(position, board);
            foreach (Position pos in positions)
                if (pos.IsOnBoard() && !board.IsPositionEmpty(pos) && board.getFigure(pos).Color != Color)
                    retList.Add(pos);
            return retList;
        }
        private List<Position> GetPossiblyPosition(Position position, Board board)
        {
            List<Position> positions = new List<Position>();
            string letters = "XXabcdefghXX";
            int indexChar = letters.IndexOf(position.Letter);
            int indexNum = position.Number;
            positions.Add(new Position(letters[indexChar - 1], indexNum - 2));
            positions.Add(new Position(letters[indexChar + 1], indexNum - 2));
            positions.Add(new Position(letters[indexChar - 1], indexNum + 2));
            positions.Add(new Position(letters[indexChar + 1], indexNum + 2));
            positions.Add(new Position(letters[indexChar - 2], indexNum - 1));
            positions.Add(new Position(letters[indexChar + 2], indexNum - 1));
            positions.Add(new Position(letters[indexChar - 2], indexNum + 1));
            positions.Add(new Position(letters[indexChar + 2], indexNum + 1));
            return positions;
        }
    }
}
